﻿/*****************************************************************//**
 * @file    FITKGraphObjectMeshModelBase.h
 * @brief   Graph object base for mesh models, such as 'part' and 'instance'.
 * 
 * @sa
 * FITKGraphObjectModelHighlighting
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-03-20
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTMESHMODELBASE_H__
#define __FITKGRAPHOBJECTMESHMODELBASE_H__

#include "FITKGraphObjectModelBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

#include <QColor>

// Forward declaration
class QVariant;

class vtkActor;
class vtkAlgorithm;

class FITKGraphActor;
class FITKHighOrderCellFilter;
class FITKShellFeatureEdges;
class FITKSurfaceFilter;

namespace Interface
{
    class FITKAbstractModel;
    class FITKUnstructuredMeshVTK;
    class FITKMeshFeatureVTK;
    class FITKModelSet;
    class FITKAbaMeshPartVTK;
}

namespace Exchange
{
    /**
     * @brief   Graph object base for mesh models, such as 'part' and 'instance'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-03-25
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectMeshModelBase : public FITKGraphObjectModelBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectMeshModelBase, FITKGraphObjectModelBase);
        FITKCLASS(Exchange, FITKGraphObjectMeshModelBase);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   model: The input data need to be exchanged
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-03-25
         */
        FITKGraphObjectMeshModelBase(AbaqusData::FITKDataCase* caseData, Interface::FITKAbstractModel* model);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-03-20
         */
        virtual ~FITKGraphObjectMeshModelBase() = default;

        /**
         * @brief   Show or hide the model points.[virtual][override]
         * @param   visible: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-18
         */
        virtual void setPointVisible(bool visible) override;

        /**
         * @brief   Set the point properties if the points are visible.[virtual][overide]
         * @param   pixelSize: The point pixel size[default]
         * @param   color: The point color[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-18
         */
        virtual void setPointProperties(int pixelSize = 8, QColor color = Qt::green) override;

        /**
         * @brief   Show or hide graph object.[virtual][override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-08
         */
        virtual void setVisible(bool visibility) override;

        /**
         * @brief   Update the visibility of actors.[virtual][override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-13
         */
        virtual void update(bool forceUpdate = false) override;

        /**
         * @brief   Set the model render mode.
         * @param   mode: The render mode
         * @param   color: The mode will need a surface color in some time( For 'Hidden' )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-07
         */
        void setRenderModel(ModelViewMode mode, QColor color = QColor());

        /**
         * @brief   Set the transparency enabled.
         * @param   isOn: Enabled or not
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-07
         */
        void setEnableTranslucency(bool isOn);

        /**
         * @brief   Set the transparency for the model's face.
         * @param   value: The transparency
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-07
         */
        void setTranslucency(double value);

        /**
         * @brief   Set the visibility of the model's feature edge actor.[virtual][override]
         * @param   visibility: The visibility of the actor
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-23
         */
        virtual void setFeatureVisible(bool visibility) override;

        /**
         * @brief   Enable back face color.[virtual][override]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        virtual void colorByDoubleFaces(bool forceUpdate = false) override;

        /**
         * @brief   Highlight model.[virtual][override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-17
         */
        virtual void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight model.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-17
         */
        virtual void disHighlight() override;

        /**
         * @brief   Pre-highlight the graph actors.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-11-29
         */
        virtual void preHighlight() override;

        /**
         * @brief   Simplified the graph object if necessary.[virtual][override]
         * @param   enabled: Enabled simplified flag
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-07
         */
        virtual void simplified(bool enabled) override;

        /**
         * @brief   Set if the graph object can be picked.[virtual][override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-23
         */
        virtual void setPickable(bool isPickable, int dim = -1) override;

    protected:
        /**
         * @brief   Constructor.( For copying data )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        FITKGraphObjectMeshModelBase() = default;

        /**
         * @brief   Initialize the surface actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-30
         */
        void initActors();

        /**
         * @brief   Initialize the feature edge actor if the model is shell.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-03
         */
        void initFeatureActor();

        /**
         * @brief   Get the visibility from the data object.
         * @return  The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-13
         */
        bool getDataVisibility() override;

        /**
         * @brief   Set the part's actor to the default model color.
         * @param   partModel: Part data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-09
         */
        void colorByDefaultForPart(Core::FITKAbstractDataObject* partModel);

        /**
         * @brief   Set the part's actor to the material's color.
         * @param   partModel: Part data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        void colorByMaterialForPart(Core::FITKAbstractDataObject* partModel);

        /**
         * @brief   Set the part's actor to the section's color.
         * @param   partModel: Part data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        void colorBySectionForPart(Core::FITKAbstractDataObject* partModel);

        /**
         * @brief   Set the part's actor to the mesh's color.
         * @param   partModel: Part data
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-13
         */
        void colorByDefaultMeshForPart(Core::FITKAbstractDataObject* partModel);

        /**
         * @brief   Get set's ids for custom type and generated type.
         * @param   set: The set data
         * @param   Indice: The indice of set members[quote]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        void getSetIds(Interface::FITKModelSet* set, QList<int> & indice);

        /**
         * @brief   Initialize the actor's visualization properties.[virtual][override]
         * @param   actor: The actor
         * @param   details: No used
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-07
         */
        virtual void initActorProperties(vtkProp* actor, QVariant details = QVariant()) override;

        /**
         * @brief   Set the model render mode for internal.
         * @param   mode: The render mode
         * @param   color: This mode will need a surface color in some time( For 'Hidden' )[quote]
         * @return  Return if the mode is supported
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-08
         */
        bool setRenderModelPrivate(ModelViewMode mode, QColor & color);
 
    protected:
        /**
         * @brief   The surface color for render mode 'Hidden'.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-08
         */
        QColor m_surfaceColorForHidden = QColor();

        /**
         * @brief   Current view mode of the model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-08
         */
        ModelViewMode m_viewMode = ModelViewMode::ModelShaded;

        /**
         * @brief   Is the model can be rendered translucencily.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-09
         */
        bool m_enabledTranslucency = false;

        /**
         * @brief   If the model is full( All elements are visible. ).
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        bool m_isModelFull = true;

        /**
         * @brief   The translucency value.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-09
         */
        double m_translucency = 0.;

        /**
         * @brief   Surface actor for visualization.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-03-25
         */
        FITKGraphActor* m_fActorFace{ nullptr };

        /**
         * @brief   Point actor for external visualization.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-20
         */
        FITKGraphActor* m_fActorPoint{ nullptr };

        /**
         * @brief   Face actor for visualization in 'Hidden' mode
         *          or the edge actor in 'Shaded' mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-08
         */
        FITKGraphActor* m_fActorAddin{ nullptr };

        /**
         * @brief   Feature edge data actor for visualization
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-03-25
         */
        FITKGraphActor* m_fActorFeature{ nullptr };

        /**
         * @brief   The manager of VTK model data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-03
         */
        Interface::FITKAbaMeshPartVTK* m_meshData{ nullptr };

        /**
         * @brief   The feature data struct for model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-02
         */
        Interface::FITKMeshFeatureVTK* m_featureMesh{ nullptr };

        /**
         * @brief   The color map of the model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        FITKColorMap* m_colorMap{ nullptr };

        /**
         * @brief   The high-order cell line removal filter for mesh data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        FITKHighOrderCellFilter* m_highOrderCellFilter{ nullptr };

        /**
         * @brief   The feature edge filter ( may be with a vtkTransformFilter ) for mesh data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        vtkAlgorithm* m_modelEdgeFilter{ nullptr };

        /**
         * @brief   The high-order cell line removal filter or the vtkTransformFilter for mesh data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        vtkAlgorithm* m_modelFilter{ nullptr };

        /**
         * @brief   The feature and bound edge filter for mesh data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        FITKShellFeatureEdges* m_featureEdgeFilter{ nullptr };

        /**
         * @brief   If the model is a shell model.( For enabling double faces property )
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-26
         */
        bool m_isShellModel = false;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTMESHMODELBASE_H__
